home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mfs055 / filesys.h < prev    next >
C/C++ Source or Header  |  1992-04-12  |  14KB  |  439 lines

  1. /*
  2.  * NOTE: This file only works if sizeof(int) == 2!
  3.  * UNLESS: you have an ANSI compiler and use prototypes
  4.  *
  5.  * Copyright 1991,1992 Eric R. Smith. This file may be re-distributed
  6.  * as long as this notice remains intact.
  7.  */
  8.  
  9. #ifndef _filesys_h
  10. #define _filesys_h
  11.  
  12. #ifndef P_
  13. # ifdef __STDC__
  14. #  define P_(x) x
  15. # else
  16. #  define P_(x) ()
  17. # endif
  18. #endif
  19.  
  20. #ifndef _wORD
  21. #ifdef __MSHORT__        /* 16 bit integers? */
  22. #define _wORD int
  23. #else
  24. #define _wORD short
  25. #endif
  26. #endif
  27.  
  28. #define NAME_MAX 32
  29. #define PATH_MAX 128
  30.  
  31. struct filesys;        /* forward declaration */
  32. struct devdrv;        /* ditto */
  33.  
  34. typedef struct f_cookie {
  35.     struct filesys *fs;    /* filesystem that knows about this cookie */
  36.     unsigned short    dev;        /* device info (e.g. Rwabs device number) */
  37.     unsigned short    aux;        /* extra data that the file system may want */
  38.     long    index;        /* this+dev uniquely identifies a file */
  39. } fcookie;
  40.  
  41. /* structure for opendir/readdir/closedir */
  42. typedef struct dirstruct {
  43.     fcookie fc;        /* cookie for this directory */
  44.     unsigned short    index;        /* index of the current entry */
  45.     unsigned short    flags;        /* flags (e.g. tos or not) */
  46. #define TOS_SEARCH    0x01
  47.     char    fsstuff[60];    /* anything else the file system wants */
  48.                 /* NOTE: this must be at least 45 bytes */
  49. } DIR;
  50.  
  51. /* structure for getxattr */
  52. typedef struct xattr {
  53.     unsigned short    mode;
  54. /* file types */
  55. #define S_IFMT    0170000        /* mask to select file type */
  56. #define S_IFCHR    0020000        /* BIOS special file */
  57. #define S_IFDIR    0040000        /* directory file */
  58. #define S_IFREG 0100000        /* regular file */
  59. #define S_IFIFO 0120000        /* FIFO */
  60. #define S_IMEM    0140000        /* memory region or process */
  61. #define S_IFLNK    0160000        /* symbolic link */
  62.  
  63. /* special bits: setuid, setgid, sticky bit */
  64. #define S_ISUID    04000
  65. #define S_ISGID 02000
  66. #define S_ISVTX    01000
  67.  
  68. /* file access modes for user, group, and other*/
  69. #define S_IRUSR    0400
  70. #define S_IWUSR 0200
  71. #define S_IXUSR 0100
  72. #define S_IRGRP 0040
  73. #define S_IWGRP    0020
  74. #define S_IXGRP    0010
  75. #define S_IROTH    0004
  76. #define S_IWOTH    0002
  77. #define S_IXOTH    0001
  78. #define DEFAULT_DIRMODE (0777)
  79. #define DEFAULT_MODE    (0666)
  80.     long    index;
  81.     unsigned short    dev;
  82.     unsigned short    reserved1;
  83.     unsigned short    nlink;
  84.     unsigned short    uid;
  85.     unsigned short    gid;
  86.     long    size;
  87.     long    blksize, nblocks;
  88.     short    mtime, mdate;
  89.     short    atime, adate;
  90.     short    ctime, cdate;
  91.     short    attr;
  92.     short    reserved2;
  93.     long    reserved3[2];
  94. } XATTR;
  95.  
  96. typedef struct fileptr {
  97.     short    links;        /* number of copies of this descriptor */
  98.     unsigned short    flags;        /* file open mode and other file flags */
  99.     long    pos;        /* position in file */
  100.     long    devinfo;    /* device driver specific info */
  101.     fcookie    fc;        /* file system cookie for this file */
  102.     struct devdrv *dev; /* device driver that knows how to deal with this */
  103.     struct fileptr *next; /* link to next fileptr for this file */
  104. } FILEPTR;
  105.  
  106. /* lock structure */
  107. struct flock {
  108.     short l_type;            /* type of lock */
  109. #define F_RDLCK        O_RDONLY
  110. #define F_WRLCK        O_WRONLY
  111. #define F_UNLCK        3
  112.     short l_whence;            /* SEEK_SET, SEEK_CUR, SEEK_END */
  113.     long l_start;            /* start of locked region */
  114.     long l_len;            /* length of locked region */
  115.     short l_pid;            /* pid of locking process
  116.                         (F_GETLK only) */
  117. };
  118.  
  119. /* LOCK structure used by the kernel internally */
  120.  
  121. typedef struct ilock {
  122.     struct flock l;
  123.     struct ilock *next;
  124.     long  reserved[4];
  125. } LOCK;
  126.  
  127. typedef struct devdrv {
  128.     long (*open)    P_((FILEPTR *f));
  129.     long (*write)    P_((FILEPTR *f, char *buf, long bytes));
  130.     long (*read)    P_((FILEPTR *f, char *buf, long bytes));
  131.     long (*lseek)    P_((FILEPTR *f, long where, _wORD whence));
  132.     long (*ioctl)    P_((FILEPTR *f, _wORD mode, void *buf));
  133.     long (*datime)    P_((FILEPTR *f, _wORD *timeptr, _wORD rwflag));
  134.     long (*close)    P_((FILEPTR *f, _wORD pid));
  135.     long (*select)    P_((FILEPTR *f, long proc, _wORD mode));
  136.     void (*unselect) P_((FILEPTR *f, long proc, _wORD mode));
  137.     long    reserved[3];    /* reserved for future use */
  138. } DEVDRV;
  139.  
  140. typedef struct filesys {
  141.     struct    filesys    *next;    /* link to next file system on chain */
  142.     long    fsflags;
  143. #define FS_KNOPARSE    0x01    /* kernel shouldn't do parsing */
  144. #define FS_CASESENSITIVE    0x02    /* file names are case sensitive */
  145. #define FS_NOXBIT    0x04    /* if a file can be read, it can be executed */
  146.  
  147.     long    (*root) P_((_wORD drv, fcookie *fc));
  148.     long    (*lookup) P_((fcookie *dir, char *name, fcookie *fc));
  149.     long    (*creat) P_((fcookie *dir, char *name, unsigned _wORD mode,
  150.                 _wORD attrib, fcookie *fc));
  151.     DEVDRV *(*getdev) P_((fcookie *fc, long *devspecial));
  152.     long    (*getxattr) P_((fcookie *fc, XATTR *xattr));
  153.     long    (*chattr) P_((fcookie *fc, _wORD attr));
  154.     long    (*chown) P_((fcookie *fc, _wORD uid, _wORD gid));
  155.     long    (*chmode) P_((fcookie *fc, unsigned _wORD mode));
  156.     long    (*mkdir) P_((fcookie *dir, char *name, unsigned _wORD mode));
  157.     long    (*rmdir) P_((fcookie *dir, char *name));
  158.     long    (*remove) P_((fcookie *dir, char *name));
  159.     long    (*getname) P_((fcookie *relto, fcookie *dir, char *pathname));
  160.     long    (*rename) P_((fcookie *olddir, char *oldname,
  161.                 fcookie *newdir, char *newname));
  162.     long    (*opendir) P_((DIR *dirh, _wORD tosflag));
  163.     long    (*readdir) P_((DIR *dirh, char *nm, _wORD nmlen, fcookie *fc));
  164.     long    (*rewinddir) P_((DIR *dirh));
  165.     long    (*closedir) P_((DIR *dirh));
  166.     long    (*pathconf) P_((fcookie *dir, _wORD which));
  167.     long    (*dfree) P_((fcookie *dir, long *buf));
  168.     long    (*writelabel) P_((fcookie *dir, char *name));
  169.     long    (*readlabel) P_((fcookie *dir, char *name, _wORD namelen));
  170.     long    (*symlink) P_((fcookie *dir, char *name, char *to));
  171.     long    (*readlink) P_((fcookie *dir, char *buf, _wORD len));
  172.     long    (*hardlink) P_((fcookie *fromdir, char *fromname,
  173.                 fcookie *todir, char *toname));
  174.     long    (*fscntl) P_((fcookie *dir, char *name, _wORD cmd, long arg));
  175.     long    (*dskchng) P_((_wORD drv));
  176.     long    zero;
  177. } FILESYS;
  178.  
  179. /*
  180.  * this is the structure passed to loaded file systems to tell them
  181.  * about the kernel
  182.  */
  183.  
  184. typedef long (*_LongFunc)();
  185.  
  186. struct kerinfo {
  187.     short    maj_version;    /* kernel version number */
  188.     short    min_version;    /* minor kernel version number */
  189.     unsigned short default_mode;    /* default file access mode */
  190.     short    reserved1;    /* room for expansion */
  191.  
  192. /* OS functions */
  193.     _LongFunc *bios_tab;     /* pointer to the BIOS entry points */
  194.     _LongFunc *dos_tab;    /* pointer to the GEMDOS entry points */
  195.  
  196. /* media change vector */
  197.     void    (*drvchng) P_((short));
  198.  
  199. /* Debugging stuff */
  200.     void    (*trace) P_((char *, ...));
  201.     void    (*debug) P_((char *, ...));
  202.     void    (*alert) P_((char *, ...));
  203.     void    (*fatal) P_((char *, ...));
  204.  
  205. /* memory allocation functions */
  206.     void *    (*kmalloc) P_((long));
  207.     void    (*kfree) P_((void *));
  208.     void *    (*umalloc) P_((long));
  209.     void    (*ufree) P_((void *));
  210.  
  211. /* utility functions for string manipulation */
  212.     short    (*strnicmp) P_((char *, char *, _wORD));
  213.     short    (*stricmp) P_((char *, char *));
  214.     char *    (*strlwr) P_((char *));
  215.     char *    (*strupr) P_((char *));
  216.     short    (*sprintf) P_((char *, char *, ...));
  217.  
  218. /* utility functions for manipulating time */
  219.     void    (*millis_time) P_((unsigned long, _wORD *));
  220.     long    (*unixtim) P_((unsigned _wORD, unsigned _wORD));
  221.     long    (*dostim) P_((long));
  222.  
  223. /* utility functions for dealing with pauses */
  224.     void    (*nap) P_((unsigned short));
  225.     void    (*sleep) P_((_wORD que, long cond));
  226.     void    (*wake) P_((_wORD que, long cond));
  227.     void    (*wakeselect) P_((long param));
  228.  
  229. /* file system utility functions */
  230.     short    (*denyshare) P_((FILEPTR *, FILEPTR *));
  231.     LOCK *  (*denylock) P_((LOCK *, LOCK *));
  232.  
  233. /* reserved for future use */
  234.     long    res2[9];
  235. };
  236.  
  237. /* flags for open() modes */
  238. #define O_RWMODE      0x03    /* isolates file read/write mode */
  239. #    define O_RDONLY    0x00
  240. #    define O_WRONLY    0x01
  241. #    define O_RDWR    0x02
  242. #    define O_EXEC    0x03    /* execute file; used by kernel only */
  243.  
  244. #define O_SHMODE    0x70    /* isolates file sharing mode */
  245. #    define O_COMPAT    0x00    /* compatibility mode */
  246. #    define O_DENYRW    0x10    /* deny both read and write access */
  247. #    define O_DENYW    0x20    /* deny write access to others */
  248. #    define O_DENYR    0x30    /* deny read access to others */
  249. #    define O_DENYNONE 0x40    /* don't deny any access to others */
  250.  
  251. #define O_NOINHERIT    0x80    /* this is currently ignored by MiNT */
  252.  
  253. #define O_NDELAY    0x100    /* don't block for i/o on this file */
  254. #define O_CREAT        0x200    /* create file if it doesn't exist */
  255. #define O_TRUNC        0x400    /* truncate file to 0 bytes if it does exist */
  256. #define O_EXCL        0x800    /* fail open if file exists */
  257.  
  258. #define O_USER        0x0fff    /* isolates user-settable flag bits */
  259.  
  260. #define O_GLOBAL    0x1000    /* for Fopen: opens a global file handle */
  261.  
  262. /* kernel mode bits -- the user can't set these! */
  263. #define O_TTY        0x2000    /* FILEPTR refers to a terminal */
  264. #define O_HEAD        0x4000    /* FILEPTR is the master side of a fifo */
  265. #define O_LOCK        0x8000    /* FILEPTR has had locking Fcntl's performed */
  266.  
  267.  
  268. /* GEMDOS file attributes */
  269.  
  270. /* macros to be applied to FILEPTRS to determine their type */
  271. #define is_terminal(f) (f->flags & O_TTY)
  272.  
  273. /* lseek() origins */
  274. #define    SEEK_SET    0        /* from beginning of file */
  275. #define    SEEK_CUR    1        /* from current location */
  276. #define    SEEK_END    2        /* from end of file */
  277.  
  278. /* The requests for Dpathconf() */
  279. #define DP_IOPEN    0    /* internal limit on # of open files */
  280. #define DP_MAXLINKS    1    /* max number of hard links to a file */
  281. #define DP_PATHMAX    2    /* max path name length */
  282. #define DP_NAMEMAX    3    /* max length of an individual file name */
  283. #define DP_ATOMIC    4    /* # of bytes that can be written atomically */
  284. #define DP_TRUNC    5    /* file name truncation behavior */
  285. #    define    DP_NOTRUNC    0    /* long filenames give an error */
  286. #    define    DP_AUTOTRUNC    1    /* long filenames truncated */
  287. #    define    DP_DOSTRUNC    2    /* DOS truncation rules in effect */
  288.  
  289. #define DP_MAXREQ    5    /* highest legal request */
  290.  
  291. /* Dpathconf and Sysconf return this when a value is not limited
  292.    (or is limited only by available memory) */
  293.  
  294. #define UNLIMITED    0x7fffffffL
  295.  
  296. /* various character constants and defines for TTY's */
  297. #define MiNTEOF 0x0000ff1a    /* 1a == ^Z */
  298.  
  299. /* defines for tty_read */
  300. #define RAW    0
  301. #define COOKED    0x1
  302. #define NOECHO    0
  303. #define ECHO    0x2
  304. #define ESCSEQ    0x04        /* cursor keys, etc. get escape sequences */
  305.  
  306. /* constants for various Fcntl commands */
  307. /* constants for Fcntl calls */
  308. #define F_DUPFD        0        /* handled by kernel */
  309. #define F_GETFD        1        /* handled by kernel */
  310. #define F_SETFD        2        /* handled by kernel */
  311. #    define FD_CLOEXEC    1    /* close on exec flag */
  312.  
  313. #define F_GETFL        3        /* handled by kernel */
  314. #define F_SETFL        4        /* handled by kernel */
  315. #define F_GETLK        5
  316. #define F_SETLK        6
  317.  
  318. #define FSTAT        (('F'<< 8) | 0)    /* handled by kernel */
  319. #define FIONREAD    (('F'<< 8) | 1)
  320. #define FIONWRITE    (('F'<< 8) | 2)
  321. #define TIOCGETP    (('T'<< 8) | 0)
  322. #define TIOCSETP    (('T'<< 8) | 1)
  323. #define TIOCSETN    TIOCSETP
  324. #define TIOCGETC    (('T'<< 8) | 2)
  325. #define TIOCSETC    (('T'<< 8) | 3)
  326. #define TIOCGLTC    (('T'<< 8) | 4)
  327. #define TIOCSLTC    (('T'<< 8) | 5)
  328. #define TIOCGPGRP    (('T'<< 8) | 6)
  329. #define TIOCSPGRP    (('T'<< 8) | 7)
  330. #define TIOCFLUSH    (('T'<< 8) | 8)
  331. #define TIOCSTOP    (('T'<< 8) | 9)
  332. #define TIOCSTART    (('T'<< 8) | 10)
  333. #define TIOCGWINSZ    (('T'<< 8) | 11)
  334. #define TIOCSWINSZ    (('T'<< 8) | 12)
  335. #define TIOCGXKEY    (('T'<< 8) | 13)
  336. #define TIOCSXKEY    (('T'<< 8) | 14)
  337.  
  338. #define PPROCADDR    (('P'<< 8) | 1)
  339. #define PBASEADDR    (('P'<< 8) | 2)
  340. #define PCTXTSIZE    (('P'<< 8) | 3)
  341.  
  342. /* terminal control constants (tty.sg_flags) */
  343. #define T_CRMOD        0x0001
  344. #define T_CBREAK    0x0002
  345. #define T_ECHO        0x0004
  346. #define T_RAW        0x0010
  347. #define T_TOS        0x0080
  348. #define T_TOSTOP    0x0100
  349. #define T_XKEY        0x0200        /* Fread returns escape sequences for
  350.                        cursor keys, etc. */
  351.  
  352. /* the following are terminal status flags (tty.state) */
  353. /* (the low byte of tty.state indicates a part of an escape sequence still
  354.  * hasn't been read by Fread, and is an index into that escape sequence)
  355.  */
  356. #define TS_ESC        0x00ff
  357. #define TS_HOLD        0x1000        /* hold (e.g. ^S/^Q) */
  358. #define TS_COOKED    0x8000        /* interpret control chars */
  359.  
  360. /* structures for terminals */
  361. struct tchars {
  362.     char t_intrc;
  363.     char t_quitc;
  364.     char t_startc;
  365.     char t_stopc;
  366.     char t_eofc;
  367.     char t_brkc;
  368. };
  369.  
  370. struct ltchars {
  371.     char t_suspc;
  372.     char t_dsuspc;
  373.     char t_rprntc;
  374.     char t_flushc;
  375.     char t_werasc;
  376.     char t_lnextc;
  377. };
  378.  
  379. struct sgttyb {
  380.     char sg_ispeed;
  381.     char sg_ospeed;
  382.     char sg_erase;
  383.     char sg_kill;
  384.     unsigned short sg_flags;
  385. };
  386.  
  387. struct winsize {
  388.     short    ws_row;
  389.     short    ws_col;
  390.     short    ws_xpixel;
  391.     short    ws_ypixel;
  392. };
  393.  
  394. struct xkey {
  395.     short    xk_num;
  396.     char    xk_def[8];
  397. };
  398.  
  399. struct tty {
  400.     short        pgrp;        /* process group of terminal */
  401.     short        state;        /* terminal status, e.g. stopped */
  402.     short        use_cnt;    /* number of times terminal is open */
  403.     short        res1;        /* reserved for future expansion */
  404.     struct sgttyb     sg;
  405.     struct tchars     tc;
  406.     struct ltchars     ltc;
  407.     struct winsize    wsiz;
  408.     long        rsel;        /* selecting process for read */
  409.     long        wsel;        /* selecting process for write */
  410.     char        *xkey;        /* extended keyboard table */
  411.     long        rsrvd[3];    /* reserved for future expansion */
  412. };
  413.  
  414. /* defines and declarations for Dcntl operations */
  415.  
  416. #define DEV_INSTALL    0xde02
  417. #define DEV_NEWBIOS    0xde01
  418. #define DEV_NEWTTY    0xde00
  419.  
  420. struct dev_descr {
  421.     DEVDRV    *driver;
  422.     short    dinfo;
  423.     short    flags;
  424.     struct tty *tty;
  425.     long    reserved[4];
  426. };
  427.  
  428. /* defines for TOS attribute bytes */
  429. #ifndef FA_RDONLY
  430. #define           FA_RDONLY           0x01
  431. #define           FA_HIDDEN           0x02
  432. #define           FA_SYSTEM           0x04
  433. #define           FA_LABEL               0x08
  434. #define           FA_DIR               0x10
  435. #define           FA_CHANGED           0x20
  436. #endif
  437.  
  438. #endif _filesys_h
  439.